﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class a_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strIP = "218.85.152.99";//WebBase.GetClientIP.ClientIP();//获取ip
        string strSpider = DalEx.ReadDOS.ExecuteDos("nslookup -qt=ptr " + strIP, 0);//获取dos命令
        
        string[] strArrIPS = strIP.Split('.');//ip分解        
        string strFJ_IP = strArrIPS[3] + "." + strArrIPS[2] + "." + strArrIPS[1] + "." + strArrIPS[0];//反解析ip

        string strANote = "";

        bool iRefWebBool = false;
        //域名反解判断
        if (strSpider.IndexOf(strFJ_IP) != -1)
        {
            strSpider = strSpider.Remove(0, strSpider.IndexOf(strFJ_IP));
            try
            {
                strANote = strSpider.Replace("name =", "#").Replace("\n", "#").Split('#')[1];
            }
            catch
            { }
            if (!string.IsNullOrEmpty(strSpider))
            {
                DataSet temp_ym = Dal.ServerWebDal.Select("StateR=1");
                Model.ServerWeb modelServerWeb = new Model.ServerWeb();
                foreach (DataRow rowi in temp_ym.Tables[0].Rows)
                {
                    if (strSpider.ToUpper().IndexOf(rowi["spider"].ToString().ToUpper()) != -1)
                    {
                        modelServerWeb = new Model.ServerWeb(rowi);
                        if (modelServerWeb.LastTime.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
                        {
                            modelServerWeb.LastTime = DateTime.Now;
                            Dal.ServerWebDal.Update(modelServerWeb);
                        }
                        iRefWebBool = true;
                    }
                }
            }
        }
        //////////////////////////////////////////////
        //插入日志
        //////////////////////////////////////////////
        Model.DbActionLog actionLog = new Model.DbActionLog();
        actionLog.AUId = "0";
        actionLog.ADateTime = DateTime.Now;
        actionLog.ANote = "注意：该IP有可能是爬虫或人工误点！\t\r" + strANote;
        actionLog.AIpaddress = WebBase.GetClientIP.getIPAddress2Num().ToString();
        actionLog.AOS = WebBase.Comm.GetOS;
        actionLog.ABrowse = WebBase.Comm.GetUserBrowser;
        Dal.DbActionLogDal.Insert(actionLog);
        //////////////////////////////////////////////

        if (!iRefWebBool)
        {
            //IP判断
            bool iRetBool = DalEx.ReadDOS.ReadIP(strArrIPS);
            if (iRetBool)
            {
                Response.Redirect("../default.aspx");
            }
            else
            {
                Response.Redirect("404.aspx");
            }
        }
        else
        {
            Response.Redirect("../default.aspx");
        }
    }
}
